package com.the_ring.behavior.chain;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: t22306139
 * @date: 2023/12/1  14:23
 */
public class FilterChainImpl implements FilterChain{

    private List<Filter> filters = new ArrayList<>();
    private int pos = 0;

    public FilterChainImpl addFilter(Filter filter) {
        filters.add(filter);
        return this;
    }

    @Override
    public void doFilter() {
        if (pos < filters.size()) {
            Filter filter = filters.get(pos++);
            filter.doFilter(this);
        }
    }
}
